package cn.datastructure.c_stack;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 */
public class StackT1 {
    public static void main(String[] args) {

//        LocalDate start = LocalDate.of(2022, 8, 24);
//
//        LocalDate end = LocalDate.of(2022, 8, 28);
//
//
//        LocalDate da = LocalDate.of(2022, 8, 24);
//        LocalDate da1 = LocalDate.of(2022, 8, 28);
//        LocalDate da3 = LocalDate.of(2022, 8, 25);
//
//        System.out.println(start.compareTo(da) <= 0 && end.compareTo(da) >= 0);
//        System.out.println(start.compareTo(da1) <= 0 && end.compareTo(da1) >= 0);
//        System.out.println(start.compareTo(da3) <= 0 && end.compareTo(da3) >= 0);
        String content = "${date}-${date,yyyy-dd-MM}${name,age}-1111";
        Pattern regex = Pattern.compile("\\$\\{([^}]*)\\}");
        Matcher matcher = regex.matcher(content);


        LocalDateTime now1 = LocalDateTime.now();
        System.out.println(now1.format(DateTimeFormatter.ISO_DATE));

        Map<String, String> val = new HashMap<>();
        val.put("date", "2022-01-02");
        while (matcher.find()) {
            String key = matcher.group(1).trim();
            String v = "";
            if (val.get(key) != null) {
                v = val.get(key);
            } else {
                if (key.startsWith("date")) {
                    String[] split = key.split(",");
                    LocalDateTime now = now1;
                    DateTimeFormatter defaultFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
                    if (split.length > 1) {
                        defaultFormatter = DateTimeFormatter.ofPattern(split[1].trim());
                    }
                    v = now.format(defaultFormatter);
                 //   val.put("date", v);
                }
            }
            content = content.replace(matcher.group(), v);
        }

        System.out.println(content);


    }
}
